import * as THREE from 'three'
export default class WaterMaterials1 {
  constructor() {
    const material = new THREE.ShaderMaterial({
      uniforms: {
        iTime: {
          value: 0,
        },
        resolution: {
          value: new THREE.Vector2(11, 1),
        },
      },
      side: THREE.DoubleSide,
      depthWrite: true,
      transparent: false,
      vertexShader: `varying vec2 vUv;
      void main() {
        vUv = uv;
        gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
      }`,
      fragmentShader: `precision highp float;
      precision highp int;
      const vec2 resolution = vec2(11.0,1.0);
      uniform vec2 mouse;
      uniform float iTime;
      varying vec2 vUv;
      mat2 rotate2D(float r)  {
          return mat2(cos(r), sin(r), -sin(r), cos(r));
      }
      void main() {
        vec2 uv = (vUv - .5 * resolution.xy) / resolution.y;
        vec3 col = vec3(0);
        float t = iTime;
        vec2 n = vec2(0), q;
        vec2 N = vec2(0);
        vec2 p = uv + sin(t * 0.1) / 10.;
        float S = 10.;
        mat2 m = rotate2D(1. - mouse.x * 0.0001);
        for (float j = 0.; j < 30.; j++) 
        {
            p *= m;
            n *= m;
            q = p * S + j + n + t;
            n += sin(q);
            N += cos(q) / S;
            S *= 1.2;
        }
        col = vec3(1, 2, 4) * pow((N.x + N.y + 0.2) + .005 / length(N), 2.1);
        gl_FragColor = vec4(col, 1.0);
    } `,
    })
    return material
  }
}
